package com.mdsoft.action;

import java.io.File;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.mdsoft.po.Admin;
import com.mdsoft.service.AdminService;
import com.mdsoft.service.GroupCountService;
import com.mdsoft.service.UserDataService;
import com.opensymphony.xwork2.ActionSupport;

public class AdminAction extends ActionSupport implements SessionAware {
	private static final long serialVersionUID = -1263938687300427990L;

	private Map<String, Object> session;

	private String username;
	private String password;

	private AdminService adminService;
	private UserDataService userDataService;

	public String login() {
		Admin admin = adminService.login(username, password);
		if (admin != null) {
			session.put("admin", admin);
			if (admin.getLoginCount() <= 1) {
				return "changepassword";
			}
			return SUCCESS;
		}
		return ERROR;
	}

	private File file;

	public String importExcel() {
		userDataService.importUserData(file.getAbsolutePath());

		return SUCCESS;
	}

	private int groupCount;

	private GroupCountService groupCountService;
	
	
	public String groupCount() {
		groupCountService.setGroupCount(groupCount);
		return SUCCESS;
	}
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public UserDataService getUserDataService() {
		return userDataService;
	}

	public void setUserDataService(UserDataService userDataService) {
		this.userDataService = userDataService;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}
	public int getGroupCount() {
		return groupCount;
	}

	public void setGroupCount(int groupCount) {
		this.groupCount = groupCount;
	}

	public GroupCountService getGroupCountService() {
		return groupCountService;
	}

	public void setGroupCountService(GroupCountService groupCountService) {
		this.groupCountService = groupCountService;
	}
	
	
}
